package com.wjw;

/**
 * Singleton - 双重检查所
 *
 * @author ikaros
 * @date 2024/7/18 1:38
 * @see <a href="ikaros@qq.com">mailTo: ikaros@qq.com</a>
 */
public class Singleton05 {

    // valatile 防止指令重排
    private static volatile Singleton05 instanmce;

    private Singleton05() {
    }

    public static Singleton05 getInstanmce() {
        if (instanmce != null) {
            return instanmce;
        }
        // 结合 synchronized 保证原子性, 单实例创建的可靠
        synchronized (Singleton05.class) {
            if (instanmce == null) {
                return instanmce = new Singleton05();
            }
        }
        return instanmce;
    }
}
